﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Xml.Linq;
using System.Xml.Serialization;
using Grundy.Common;
using Grundy.CryptographicServices;
using System.Linq;
using Grundy.Message;

namespace Grundy.Entity
{   
    public class LicenseManager
    {
        private readonly CryptographicServicesProvider _cryptographicServicesProvider;
        
        protected LicenseManager(){}

        public LicenseManager(CryptographicServicesProvider cryptographicServicesProvider)
        {
            _cryptographicServicesProvider = cryptographicServicesProvider;
        }

        public virtual Container CreateLicenseForEntitlement(CustomerEntitlement customerEntitlement)
        {
            var container = _cryptographicServicesProvider.Sign(customerEntitlement, ContainerSigneeType.EntitlementServer);
            return container;
        }

        public virtual CustomerEntitlement CreateCustomerEntitlementFromLicense(Container container)
        {
            var ce = _cryptographicServicesProvider.Verify<CustomerEntitlement>(container);
            return ce;
        }
    }
}